#!/bin/sh

sudo adduser judger --gecos "" --disabled-password

mv /root/jdk-7u76-linux-x64.tar.gz /root/jdk-8u31-linux-x64.tar.gz /root/conf.json /home/judger
chown judger /home/judger/jdk-7u76-linux-x64.tar.gz /home/judger/jdk-8u31-linux-x64.tar.gz /home/judger/conf.json
chgrp judger /home/judger/jdk-7u76-linux-x64.tar.gz /home/judger/jdk-8u31-linux-x64.tar.gz /home/judger/conf.json

mkdir /var/uoj_data_copy
chown judger /var/uoj_data_copy

su judger <<EOD
cd ~
mkdir judge_client_svn
cd judge_client_svn
svn co svn://__uoj_host__/judge_client __svn_cert__
cd ~
ln -s judge_client_svn/judge_client/1 judge_client
cd judge_client
echo '#define UOJ_WORK_PATH "/home/judger/judge_client/uoj_judger"' >uoj_judger/include/uoj_work_path.h
make
ln -s /var/uoj_data_copy ~/judge_client/uoj_judger/data

mkdir ~/judge_client/uoj_judger/run/runtime
mv ~/jdk-7u76-linux-x64.tar.gz ~/jdk-8u31-linux-x64.tar.gz ~/judge_client/uoj_judger/run/runtime
cd ~/judge_client/uoj_judger/run/runtime
tar -xzf jdk-7u76-linux-x64.tar.gz
tar -xzf jdk-8u31-linux-x64.tar.gz

mv ~/conf.json ~/judge_client/.conf.json
chmod 600 ~/judge_client/.conf.json
EOD
